home *** CD-ROM | disk | FTP | other *** search
- package demos.Mix;
-
- import java.applet.Applet;
- import java.applet.AudioClip;
- import java.awt.BorderLayout;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Dimension;
- import java.awt.FlowLayout;
- import java.awt.Font;
- import java.awt.GridBagConstraints;
- import java.awt.GridBagLayout;
- import java.awt.GridLayout;
- import java.awt.Window;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.WindowListener;
- import java.net.URL;
- import javax.swing.AbstractButton;
- import javax.swing.ImageIcon;
- import javax.swing.JButton;
- import javax.swing.JComponent;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- import javax.swing.JTabbedPane;
- import javax.swing.border.BevelBorder;
-
- public class JavaSound extends JPanel implements ActionListener {
- private AudioClip clip = null;
- private JButton playButton;
- private JButton loopButton;
- private Timer timer = null;
- protected static final int STOP = 0;
- protected static final int PLAY = 1;
- protected static final int LOOP = 2;
- protected int audioState = 0;
- // $FF: renamed from: f1 java.awt.Font
- private Font field_0 = new Font("serif", 3, 18);
- // $FF: renamed from: f2 java.awt.Font
- private Font field_1 = new Font("serif", 0, 14);
- static Class class$demos$Mix$JavaSound;
-
- public JavaSound() {
- ((Container)this).setLayout(new BorderLayout());
- ((JComponent)this).setBackground(Color.gray);
- String[] playType = new String[]{"mix1", "mix2", "rmf"};
- String[][] playList = new String[][]{{"sfx-medley.rmf", "trippygaia1.mid", "spacemusic.au"}, {"bong.wav", "bark.aiff", "trance.rmf"}, {"ambient.rmf", "classical.rmf", "modern-rock.rmf"}};
- JTabbedPane tabbedPane = new JTabbedPane();
- ((JComponent)tabbedPane).setBorder(new BevelBorder(0));
- ((JComponent)tabbedPane).setFont(new Font("Times New Roman", 0, 10));
-
- for(int i = 0; i < playType.length; ++i) {
- JPanel jp = new JPanel(new GridLayout(0, 1));
-
- for(int j = 0; j < playList[i].length; ++j) {
- ((Container)jp).add(new JavaSound(this, playList[i][j], false));
- }
-
- tabbedPane.addTab(playType[i], jp);
- }
-
- ((Container)this).add(tabbedPane);
- JPanel jp1 = new JPanel(new GridLayout(0, 1));
- String[] s1 = new String[]{"J", "A", "V", "A"};
-
- for(int i = 0; i < s1.length; ++i) {
- ((Container)jp1).add(this.addLabel(s1[i]));
- }
-
- ((Container)this).add("West", jp1);
- JPanel jp2 = new JPanel(new GridLayout(0, 1));
- String[] s2 = new String[]{"S", "O", "U", "N", "D"};
-
- for(int i = 0; i < s2.length; ++i) {
- ((Container)jp2).add(this.addLabel(s2[i]));
- }
-
- ((Container)this).add("East", jp2);
- }
-
- public JavaSound(JavaSound js, String name, boolean playSomeAudio) {
- Class var10000 = class$demos$Mix$JavaSound;
- if (var10000 == null) {
- try {
- var10000 = Class.forName("demos.Mix.JavaSound");
- } catch (ClassNotFoundException var9) {
- throw new NoClassDefFoundError(((Throwable)var9).getMessage());
- }
-
- class$demos$Mix$JavaSound = var10000;
- }
-
- URL url = var10000.getResource("audio/" + name);
- this.clip = Applet.newAudioClip(url);
- GridBagLayout gbl = new GridBagLayout();
- ((Container)this).setLayout(gbl);
- ((JComponent)this).setBackground(Color.gray);
- JLabel l = new JLabel(name);
- ((JComponent)l).setFont(this.field_1);
- ((JComponent)l).setForeground(Color.black);
- GridBagConstraints gbc = new GridBagConstraints();
- gbc.gridx = 0;
- gbc.gridy = 0;
- gbl.setConstraints(l, gbc);
- ((Container)this).add(l);
- JPanel p1 = new JPanel(new FlowLayout());
- ((JComponent)p1).setBackground(Color.gray);
- this.playButton = new JButton("play");
- this.playButton.setFont(this.field_1);
- this.playButton.setBackground(Color.green);
- this.playButton.addActionListener(this);
- ((Container)p1).add(this.playButton);
- this.loopButton = new JButton("loop");
- this.loopButton.setFont(this.field_1);
- this.loopButton.addActionListener(this);
- ((Container)p1).add(this.loopButton);
- this.timer = new Timer(this, js, this, this.clip);
- ((Container)p1).add(this.timer);
- gbc = new GridBagConstraints();
- gbc.gridx = 0;
- gbc.gridy = 1;
- gbl.setConstraints(p1, gbc);
- ((Container)this).add(p1);
- if (playSomeAudio) {
- this.actionPerformed(new ActionEvent(this, 1001, "play"));
- }
-
- }
-
- public void actionPerformed(ActionEvent evt) {
- if (evt.getActionCommand() == "loop") {
- this.clip.loop();
- this.timer.start();
- this.audioState = 2;
- this.playButton.setText("stop");
- this.playButton.setBackground(Color.red);
- } else if (this.audioState >= 1) {
- this.stopAudio();
- } else {
- this.playAudio();
- }
-
- }
-
- public JButton addButton(ImageIcon ii) {
- JButton b = new JButton(ii);
- ((AbstractButton)b).addActionListener(this);
- return b;
- }
-
- public JLabel addLabel(String s) {
- JLabel l = new JLabel(" " + s + " ");
- ((JComponent)l).setForeground(Color.gray);
- ((JComponent)l).setFont(this.field_0);
- return l;
- }
-
- public static void main(String[] s) {
- WindowListener l = new 1();
- JFrame f = new JFrame("Java2D Demo - JavaSound");
- ((Window)f).addWindowListener(l);
- f.getContentPane().add("Center", new JavaSound());
- ((Window)f).pack();
- ((Component)f).setSize(new Dimension(320, 260));
- ((Window)f).show();
- }
-
- public void playAudio() {
- this.clip.play();
- this.playButton.setText("stop");
- this.playButton.setBackground(Color.red);
- this.timer.start();
- this.audioState = 1;
- }
-
- public void stopAudio() {
- this.audioState = 0;
- this.clip.stop();
- this.playButton.setText("play");
- this.playButton.setBackground(Color.green);
- this.timer.stop();
- }
- }
-